<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  	<jsp:include page="../include.jsp" flush="true"/>
    <title>资料管理</title>
    
	<script type="text/javascript">
	var grid;
	var win;
	var url;
	var intistring;//判断add delete update方法
	
	$(function() {
		grid = $('#user_info').datagrid();
		$('#btn-save,#btn-cancel').linkbutton();
		win = $('#user-window').window( {
			collapsible : false,//折叠
			minimizable : false,//最小化
			maximizable : false,//最大化
			draggable : true,//拖动
			resizable : false,//改变大小
			modal : true,
			closed : true
		});
	});

	function append() {
		reject();
		win.window('open');
		status = 'enable';
		$('#userform').form('clear');
		url ='b02!uploadCourseware?user_id='+<%=session.getAttribute("user_id")%>;
	}
	function remove() {
		var rows = $('#user_info').datagrid('getSelected');
		if(!rows){
			$.messager.show( {
					title : '警告',
					msg : '请先选择一行数据。'
			})
			return false;
		}
		$.messager.confirm('提示','确定删除吗?',function(result){  
            if (result){  
                $.post('b02!removeCourseware?data_id='+rows.data_id,function(message){
                	show(message.returnMsg);
                    $('#user_info').datagrid('reload');
                });
            } 
            reject();
        });
	}
	function download(){
		var rows = $('#user_info').datagrid('getSelected');
		if(!rows){
			show("请先选择一条数据");
		}
		document.location.href ="<%=basePath%>"+rows.data_path;
	}
	function save() {
		$('#userform').form('submit', {
			url : url,
			onSubmit : function() {
				return $(this).form('validate');
			},
			success : function(data) {
				$('#user_info').datagrid('reload');
				win.window('close');
				$.messager.show( {
					title : '提示',
					msg : '执行完毕!'
				});
			}
		});
	}
	function query(){
		var params = $('#user_info').datagrid('options').queryParams; //先取得 datagrid 的查询参数  
        var fields =$('#query-form').serializeArray(); //自动序列化表单元素为JSON对象  
        $.each( fields, function(i, field){
            params[field.name] = field.value; //设置查询参数  
        });   
        $('#user_info').datagrid('reload'); //设置好查询参数 reload 一下就可以了
	}
	function reject(){
		$('#user_info').datagrid('clearSelections');
	} 
	
	function closeWindow() {
		win.window('close');
		reject();
	}
</script>
	<script type="text/javascript">
		$(function(){
			var lastIndex;
			$('#user_info').datagrid({
				fit:true,
				width:'auto',
				height:'auto',
				method:'post',
				nowrap: false,
				fitColumns:'true',
				toolbar:toolbar,
				striped: true,
				url:'b02!queryCoursewareHead?user_role_id='+<%=session.getAttribute("user_role_id")%>+'&user_id='+<%=session.getAttribute("user_id")%>,
				showFooter: true,
				idField:'data_id',
				sortOrder:'desc',//列排序
				columns:[[
					{field:'ck',checkbox:true,width:2}, //显示复选框
					{field:'data_id',title:'资料ID',align:'center',width:80,hidden:true},
					{field:'data_name',title:'标题',align:'center',width:120},
					{field:'data_note',title:'相关课题',align:'center',editor:'text',width:120},
					{field:'data_type_id',title:'数据类型',align:'center',editor:'text',width:70,hidden:true},
					{field:'data_cretime',title:'上传时间',align:'center',editor:'text',width:40},
					{field:'data_path',title:'路径',align:'center',editor:'text',width:70,hidden:true},
					{field:'data_owner_id',title:'所属教师',align:'center',editor:'text',width:120,hidden:true},
					{field:'data_flag',title:'数据标志',align:'center',editor:'text',width:20,hidden:true},
					{field:'data_report_flag',title:'小组报告',align:'center',editor:'text',width:120,hidden:true}
				]],
				rownumbers:true,
				singleSelect:true,
				onLoadSuccess:function(){  
               		$('#user_info').datagrid('clearSelections');
            	}
			})
		});
		
	</script>
  </head>
  <body>
  	<div class="easyui-layout" data-options="fit:true">
<!-- north -->
		<div data-options="region:'north',split:false,border:true" style="height:40px">
			<form id="query-form" method="post" style="padding-left:10px;">
		  		文件标题<input type="text" class="easyui-validatebox" name="dataName" style="width:90px;"></input>&nbsp;
				文件类型<input name="typeId" class="easyui-combogrid" style="width:90px" data-options="
					panelWidth: 200,
					idField: 'type_id',
					textField: 'type_id',
					url: 'b01!queryDataType',
					columns: [[
						{field:'type_name',title:'文件属性',width:80},
						{field:'type_id',title:'文件类型',width:120}
					]],
					fitColumns: true
				">&nbsp;
				相关课题<input name="dataNote" class="easyui-combogrid" style="width:90px" data-options="
					panelWidth: 200,
					idField: 'task_id',
					textField: 'task_id',
					url: 'b02!queryTask',
					columns: [[
						{field:'task_id',title:'任务简称',width:80},
						{field:'task_name',title:'任务名',width:120}
					]],
					fitColumns: true
				">
				&nbsp;&nbsp;&nbsp;
		        <a href="javascript:void(0)" onclick="query()" id="btn-save" icon="icon-search">查询</a>
		  	</form>
		</div>
<!-- center -->
		<div data-options="region:'center',border:false" title="教学资料列表">
			<table id="user_info"></table>
			<div id="user-window" title="用户窗口" style="width:450px;height:auto;">
				<div style="padding:20px 20px 40px 80px;">
					<form id="userform" method="post" enctype="multipart/form-data">
						<table>
							<tr>
								<td>
									<input type="hidden" class="easyui-validatebox" name="data_id" id="data_id">
									<s:file name="upload" label="文件上传" class="easyui-validatebox" required="true"></s:file>
		        				</td>
							</tr>
							
							<tr>
								<td>相关课题:</td>
								<td>
									<input name="data_note" class="easyui-combogrid" style="width:120px" data-options="
										panelWidth: 200,
										idField: 'task_id',
										textField: 'task_id',
										url: 'b02!queryTask',
										columns: [[
											{field:'task_id',title:'任务简称',width:80},
											{field:'task_name',title:'任务名',width:120}
										]],
										fitColumns: true
									">
								</td>
							</tr>
						</table>
					</form>
				</div>
				<div style="text-align:center;padding:5px;">
					<a href="javascript:void(0)" onclick="save()" id="btn-save" icon="icon-save">确认</a>
					<a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeWindow()" id="btn-cancel" icon="icon-cancel">取消</a>
				</div>
			</div>
		</div>
	</div>
	
	<script type="text/javascript" src="./jquery-easyui-1.3.2/easyloader.js"></script>
	<script type="text/javascript">
		if(user_role_id == 1 || user_role_id == 5){
			var toolbar = [{
				id:'addbtn',
				text:'增加',
				iconCls:'icon-add',
				handler:function(){append()}
			},{
				id:'updatebtn',
				text:'下载',
				iconCls:'icon-save',
				handler:function(){download()}
			},{
				text:'删除',
				iconCls:'icon-cut',
				handler:function(){remove()}
			},{
				text:'返回',
				iconCls:'icon-undo',
				handler:function(){reject()}
			},{
				text:'帮助',
				iconCls:'icon-help',
				handler:function(){reject()}
			}];
		}else {
			var toolbar = [{
				text:'返回',
				iconCls:'icon-undo',
				handler:function(){reject()}
			},{
				id:'updatebtn',
				text:'下载',
				iconCls:'icon-save',
				handler:function(){download()}
			},{
				text:'帮助',
				iconCls:'icon-help',
				handler:function(){reject()}
			}];
		}
		
	</script>
  </body>
</html>
